import request from '@/utils/request'
import method from '@/utils/config'

const urlPrefix = 'crm/'

// 请求路径
const receivablesApi = {
  // 按条件分页查询
  listByParamsForTable: urlPrefix + 'receivables/listByParamsForTable',
  // 根据id查询详情
  selectByPrimaryKey: urlPrefix + 'receivables/selectByPrimaryKey',
  // 保存回款信息
  saveHasKey: urlPrefix + 'receivables/saveHasKey',
  // 修改回款信息
  updateByPrimaryKeySelective: urlPrefix + 'receivables/updateByPrimaryKeySelective',
  // 根据id批量删除回款
  deleteBatchByIds: urlPrefix + 'receivables/deleteBatchByIds',
  // 修改回款负责人
  changeOwnerUser: urlPrefix + 'receivables/changeOwnerUser'
}

/**
 * 查询列表页数据
 * @param queryParams
 * @returns {*}
 */
export function listByParamsForTable(queryParams) {
  return request({
    url: receivablesApi.listByParamsForTable,
    method: method.POST,
    data: {
      page: queryParams.page,
      limit: queryParams.limit,
      search: queryParams.search
    }
  })
}

/**
 * 通过主键查询
 * @param id 主键
 * @returns {AxiosPromise}
 */
export function selectByPrimaryKey(id) {
  return request({
    url: receivablesApi.selectByPrimaryKey + `?id=${id}`,
    method: method.GET
  })
}

/**
 * 根据id批量删除数据
 * @param ids id集合
 * @returns {AxiosPromise}
 */
export function deleteBatchByIds(ids) {
  return request({
    url: receivablesApi.deleteBatchByIds + `/${ids}`,
    method: method.DELETE
  })
}

/**
 * 修改回款
 * @param data 回款数据
 * @returns {*}
 */
export function updateByPrimaryKeySelective(data) {
  return request({
    url: receivablesApi.updateByPrimaryKeySelective,
    method: method.PUT,
    data
  })
}

/**
 * 新增回款
 * @param data 回款数据
 * @returns {*}
 */
export function saveHasKey(data) {
  return request({
    url: receivablesApi.saveHasKey,
    method: method.POST,
    data
  })
}


